import java.util.concurrent.BlockingQueue;

public class MyQueueBlocking {
    public final Object locker = new Object();
    int[] arr = new int[10];
    int useSize = 0;
    int tail = 0;
    int head = 0;

    public void add(int n)  {
        synchronized (locker) {
            while (useSize == arr.length) {
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            arr[tail] = n;
            useSize++;
            //tail++;
            tail = (tail+1) % arr.length;
            locker.notify();
        }


    }

    public void pull() {
        synchronized (locker) {
            //判断里面是否为空
            while (useSize == 0) {
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            useSize--;
            //head++;
            head = (head+1) % arr.length;
            locker.notify();
        }
    }
}
BlockingQueue